package com.litengsoft.lianmeng.domain;

import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

/**
 * 微信返回值实体
 */
@Getter
@Setter
public class WebWXResponse {

    /**
     * 返回状态码
     */
    private String code;

    /**
     * 返回uuid
     */
    private String uuid;

    /**
     * 微信扫码后返回的uri
     */
    private String redirectUri;

    public WebWXResponse(String str) throws IOException {
        String[] split = str.split(";");
        if (split.length > 0) {
            for (String s : split) {
                int i = s.indexOf("=");
                if (i > -1) {
                    String key = s.trim().substring(0, i);
                    String value = s.trim().substring(i + 1);
                    if (key.contains("code")) {
                        this.code = value;
                    }
                    if (key.contains("uuid")) {
                        this.uuid = value.replaceAll("\"", "");
                    }
                    if (key.contains("redirect_uri")) {
                        this.redirectUri = value.replaceAll("\"", "");
                    }
                }
            }
        }
    }

    public static void main(String[] args) throws IOException {
        WebWXResponse s = new WebWXResponse("window.QRLogin.code = 200; window.QRLogin.uuid =\"DeA6idundY9VKn\";");
        System.out.println(JSONObject.toJSONString(s));
    }

}
